{{template "admin-layout.html" .}}

{{define  "content" }}

<div class="row">
    <div class="col-md-12">
        <h1>文章管理</h1>
        <a href="/admin/post/new" class="btn btn-primary mb-3">写文章</a>
        <table class="table table-bordered">
            <thead>
                <tr>
                    <th>标题</th>
                    <th>作者</th>
                    <th>分类</th>
                    <th>日期</th>
                    <th>操作</th>
                </tr>
            </thead>
            <tbody>
                {{range .posts}}
                <tr>
                    <td>{{.Title}}</td>
                    <td>{{.User.Name}}</td>
                    <td>
                        {{range .Categories}}
                        <span class="badge bg-secondary">{{.Name}}</span>
                        {{end}}
                    </td>
                    <td>{{.CreatedAt.Format "2006-01-02"}}</td>
                    <td>
                        <a href="/admin/post/edit/{{.ID}}" class="btn btn-sm btn-primary">编辑</a>
                        <a href="/admin/post/delete/{{.ID}}" class="btn btn-sm btn-danger" onclick="return confirm('确定要删除这篇文章吗？')">删除</a>
                    </td>
                </tr>
                {{end}}
            </tbody>
        </table>
    </div>
</div>

{{ end }}